package com.joolun.web.controller.scrm;

import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.core.page.TableDataInfo;
import com.joolun.common.enums.BusinessType;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.weixin.entity.ZbActiveConfig;
import com.joolun.weixin.service.IZbActiveConfigService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 直播活动配置Controller
 * 
 * @author joolun
 * @date 2025-04-24
 */
@RestController
@RequestMapping("/zb/config")
public class ZbActiveConfigController extends BaseController
{
    @Autowired
    private IZbActiveConfigService zbActiveConfigService;

    /**
     * 查询直播活动配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZbActiveConfig zbActiveConfig)
    {
        startPage();
        List<ZbActiveConfig> list = zbActiveConfigService.selectZbActiveConfigList(zbActiveConfig);
        return getDataTable(list);
    }

    /**
     * 导出直播活动配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    @Log(title = "直播活动配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZbActiveConfig zbActiveConfig)
    {
        List<ZbActiveConfig> list = zbActiveConfigService.selectZbActiveConfigList(zbActiveConfig);
        ExcelUtil<ZbActiveConfig> util = new ExcelUtil<ZbActiveConfig>(ZbActiveConfig.class);
        util.exportExcel(response, list, "直播活动配置数据");
    }

    /**
     * 获取直播活动配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zbActiveConfigService.selectZbActiveConfigById(id));
    }

    /**
     * 新增直播活动配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    @Log(title = "直播活动配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZbActiveConfig zbActiveConfig)
    {
        zbActiveConfig.setCreateBy(getUsername());
        return toAjax(zbActiveConfigService.insertZbActiveConfig(zbActiveConfig));
    }

    /**
     * 修改直播活动配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    @Log(title = "直播活动配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZbActiveConfig zbActiveConfig)
    {
        zbActiveConfig.setCreateBy(getUsername());
        return toAjax(zbActiveConfigService.updateZbActiveConfig(zbActiveConfig));
    }

    /**
     * 删除直播活动配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "直播活动配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zbActiveConfigService.deleteZbActiveConfigByIds(ids));
    }
}
